package com.cloud.dataway.service.impl;

import com.cloud.dataway.entity.UserEntity;
import com.cloud.dataway.mapper.UserMapper;
import com.cloud.dataway.mapper.UserSlaveMapper;
import com.cloud.dataway.service.UserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author yazhou
 * @since 2020-04-25
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, UserEntity> implements UserService {

    @Autowired
    UserSlaveMapper userSlaveMapper;

    @Transactional
    @Override
    public boolean update(UserEntity userEntity) {
        baseMapper.updateById(userEntity);

        if (userEntity.getId() == 1) {
            throw new RuntimeException("禁止修改" + userEntity.getId());
        }
        return true;
    }

    @Override
    public List<UserEntity> getSlave(){
        Integer integer = userSlaveMapper.selectCount(null);
        System.out.println(integer);
        return userSlaveMapper.selectList();
    }
}
